/**
 * @author yzhou2
 */
var NewsWebPage=function(containerId,id,objName){
    GB_NewsDataManager.dataURL.newsTitle="../demo/getNewsTitleDemo.jsp";
    GB_NewsDataManager.dataURL.newsContent="../demo/getNewsContentDemo.jsp";
    GB_NewsDataManager.dataURL.newsSource="../template.jsp";
	this.newsComponent=null;
	this.profile=null;
	this.containerId=containerId;
	this.id=id;
	this.objName=objName;	
	this.init();
};
NewsWebPage.prototype={
    init:function(){
		var qString=this._getQueryString();
		this.newsComponent= new QS_News();
		this.profile={
			symbolType:'all',
            disabledDDMenu:true,
            disableCustomView:true,
            isSaveRange:true,
			tabCloseable:false,
			terminal:'other'
		};
		if(qString["width"]&&qString["height"]){
            this.profile["width"]=parseInt(qString["width"],10);
            this.profile["height"]=parseInt(qString["height"],10);
        }
		if(qString["symbol"]){
			this.profile["symbolType"]='single';
			this.profile["ticker"]=qString["symbol"];
		}
		if(qString["fromDate"]&&qString["toDate"]){
            this.profile["fromDate"]=qString["fromDate"];
            this.profile["toDate"]=qString["toDate"];
        }
		if(qString["isShowContent"]){
            this.profile["isShowContent"]=parseInt(qString["isShowContent"],10)==0?false:true;
        }
		if(qString["openedList"]){
            this.profile["openedList"]=qString["openedList"];
        }
		if(qString["maxCount"]&&qString["maxCount"]>0){
			this.profile["maxCount"]=qString["maxCount"];
		}
		this.newsComponent.init(this.containerId,this.profile,this.id,this.objName+".newsComponent");
		this._initEvent();
	},
	changeSymbols:function(symbols){
		this.newsComponent.acceptTicker(symbols);
	},
	changeDateRange:function(s,e){//yyyy-mm-dd
		s=GB_NewsDataManager.convertDate(s),
		e=GB_NewsDataManager.convertDate(e);
		this.newsComponent.changeDateRange(s,e);
	},
	shareLink:function(){
		var paras=[],config=this.newsComponent.saveConfig(),
		link=location.protocol+"//"+location.host+location.pathname;
		if(this.profile.maxCount){
			paras.push("maxCount="+this.profile.maxCount);
		}
		for(var o in config){
			if(o=='width'||o=='height'){
				paras.push(o+"="+parseInt(config[o],10));
			}else if(o=='fromDate'||o=='toDate'){
				paras.push(o+"="+config[o]);
			}else if(o=='ticker'){
				paras.push('symbol='+config[o]);
			}
		}
		if(paras.length>0){
			link+="?"+paras.join('&');
		}
		return link;
	},
	_initEvent:function(){
		var self=this;
		$(window).bind('resize',function(e){
			self.newsComponent.changeOutSize(self.profile["width"],self.profile["height"]);
		});
	},
	_getQueryString:function(){
	   var qString={};
       var para=location.search;
       if(para&&para!=''){
          para=para.substring(1,para.length);
          var array=para.split("&"),arr=[];
          for(var i=0,l=array.length;i<l;i++){
             arr=array[i].split("=");
			 if (typeof arr[0] != 'undefined' && typeof arr[1] != 'undefined'&&arr[0]!=''&&arr[1]!='') {
			 	qString[arr[0]] = arr[1];
			 }
          };
       }
	   return qString;
	}
};